#include <iostream>
#include <string>
#include <unordered_map>
#include <set>
#include <vector>
#include <ctime>
#include <algorithm>
#include <cassert>
#include <math.h>
#include <queue>

using namespace std;

//服务器结构
struct Server{
	string type;
	int cpuA, cpuB, memA, memB, serverCost, powerCost;
	float ratio;//核内比
	float unitPrice;//单价
	//空参构造器
	Server(){}
	//带参构造器
	Server(string type, int cpuCore, int memSize, int sCost, int pCost):type(type),serverCost(sCost),powerCost(pCost){
		this->cpuA = cpuCore / 2;
		this->cpuB = this->cpuA;
		this->memA = memSize / 2;
		this->memB = this->memA;
		this->ratio = (float)cpuCore/memSize;
		this->unitPrice =  2 * (float)sCost/(cpuCore+memSize);//如果只是用来排序比大小的话，乘不乘 2 差别不大
	}
};

//虚拟机结构
struct VirtualMachine{
	string type;
	int cpuCore, memSize, isDual;
	float ratio;//核内比
	//空参构造器
	VirtualMachine(){}
	//带参构造器
	VirtualMachine(string type, int cpuCore, int memSize, int isDual):type(type),cpuCore(cpuCore),memSize(memSize),isDual(isDual){
		this->ratio = (float)cpuCore/memSize;
	}
};

//添加请求结构
struct Request{
	string type;//add or del
	string vmType, vmId;
	int vmCpu, vmMem, isDual;
	float ratio;//核内比
	Request(){}//空参构造器
	Request(string type, string vmType, string vmId, int vmCpu, int vmMem, int isDual):type(type),vmType(vmType),vmId(vmId),vmCpu(vmCpu),vmMem(vmMem),isDual(isDual){
		this->ratio = (float)vmCpu/vmMem;
	}
	//当其为一条删除请求时，只有其vmId有效，其他的数据别访问，会出错。
	Request(string type, string vmId):type(type),vmId(vmId){}
};

//对服务器，按单价排序
bool sv_cmp_unitprice_up (Server const &s1, Server const s2){
	return s1.unitPrice < s2.unitPrice;
}

//对添加请求，按cpu核进行排序
bool req_cmp_cpu_up (Request const &req1, Request const &req2){
	return req1.vmCpu < req2.vmCpu;
}
//对添加请求，按cpu核进行排序
bool req_cmp_cpu_down (Request const &req1, Request const &req2){
	return req1.vmCpu > req2.vmCpu;
}
//对添加请求，按内存进行排序
bool req_cmp_mem_up (Request const &req1, Request const &req2){
	return req1.vmMem < req2.vmMem;
}
//对添加请求，按内存进行排序
bool req_cmp_mem_down (Request const &req1, Request const &req2){
	return req1.vmMem > req2.vmMem;
}

/********* 全局变量 ***********************/
unordered_map<string, Server> svInfos;              //原始的服务器信息
unordered_map<string, VirtualMachine> vmInfos;      //原始的虚拟机信息
vector<Server> sortedServers;                       //排序的服务器（按照单价升序排）
vector<Server> greatServers;                        //核内比大于等于 1 的服务器
vector<Server> lessServers;                         //核内比小于 1 的服务器
vector<Request> dayAddReqs;                         //每日的添加请求
vector<Request> rest_dayAddReqs;
vector<Request> dayDelReqs;                         //每日的删除请求

vector<Server> svResources;
vector<int> svRunVmsNumber;
vector<vector<string>> svRunVms;
#define DeployInfo vector<int>                     //虚拟机的部署信息。{服务器编号, 总占用cpu, 总占用mem, maybe 部署节点}。长度为3->双节点部署;当长度为4->单节点部署（0-A,1->B）
unordered_map<string, DeployInfo> vmDeployInfos;

vector<vector<string>> purchase_info;//每天的购买信息
vector<vector<string>> migrate_info;//每天的迁移信息
vector<vector<string>> deploy_info;//每天的部署信息
//提交时不需要
# define INPUT_REDIRECTION_1 "training-data/training-1.txt"  //输入重定向
# define INPUT_REDIRECTION_2 "training-data/training-2.txt"  //输入重定向
# define OUTPUT_REDIRECTION "result.txt"                     //输出重定向
long long SERVERCOST=0, POWERCOST=0, TOTALCOST=0;            //各种成本
long long SC=0, PC=0, TC=0;                                  //两份数据的成本
/*****************************************/

/****************** 读数据构建各种类型的 服务器 和 虚拟机 ********************/
void readServer(string &serverType, string &cpuCore, string &memSize, string &serverCost, string &powerCost){
	string _serverType = "";
    for(int i =1; i<serverType.size()-1; i++) _serverType += serverType[i];
    int _cpuCore=0, _memSize=0, _serverCost=0, _powerCost=0;
    for(int i=0; i<cpuCore.size()-1; i++) _cpuCore = 10*_cpuCore + cpuCore[i] - '0';
    for(int i=0; i<memSize.size()-1; i++) _memSize = 10*_memSize + memSize[i] - '0';
    for(int i=0; i<serverCost.size()-1; i++) _serverCost = 10*_serverCost + serverCost[i] - '0';
    for(int i=0; i<powerCost.size()-1; i++) _powerCost = 10*_powerCost + powerCost[i] - '0';
	svInfos[_serverType] = Server{_serverType, _cpuCore, _memSize, _serverCost, _powerCost};
}
void readVm(string &vmType, string &cpuCore, string &memSize, string &isDual){
    string _vmType = "";
    for(int i=1; i<vmType.size()-1; i++) _vmType += vmType[i];
    int _cpuCore=0, _memSize=0, _isDual=0;
    for(int i=0; i<cpuCore.size()-1; i++) _cpuCore = _cpuCore*10 + cpuCore[i] - '0';
    for(int i=0; i<memSize.size()-1; i++) _memSize = _memSize*10 + memSize[i] - '0';
    if(isDual[0] == '1') _isDual = 1;
    vmInfos[_vmType] = VirtualMachine{_vmType, _cpuCore, _memSize, _isDual};
}
void readServerAndVmInfos(){
	int svNum;//服务器数量
	string type, cpuCore, memSize, serverCost, powerCost, isDual;
	scanf("%d", &svNum);
	for (int i=0; i<svNum; i++){
		cin>>type>>cpuCore>>memSize>>serverCost>>powerCost;
		readServer(type, cpuCore, memSize, serverCost, powerCost);
	}
	int vmNum;//虚拟机数量
    scanf("%d",&vmNum);
	for (int i =0; i<vmNum; i++){
        cin>>type>>cpuCore>>memSize>>isDual;
        readVm(type, cpuCore, memSize, isDual);
    }
    //复制一份排序。
    for(auto const &pair:svInfos) sortedServers.emplace_back(pair.second);
	sort(sortedServers.begin(), sortedServers.end(), sv_cmp_unitprice_up);
	//用排好序的数据，分类核内比大于1和小于1的服务器
	for(Server &sv : sortedServers){
		if (sv.ratio>=1) greatServers.emplace_back(sv);
		else lessServers.emplace_back(sv);
	}
}
/*****************************************************************************/

/************** 读数据构建每日请求 ****************/
void readAddRequest(string &op, string & reqVmType, string &reqVmId){
	string _op, _reqVmType, _reqVmId;
    _op = op.substr(1, op.size()-2);
    _reqVmType = reqVmType.substr(0, reqVmType.size()-1);
    _reqVmId = reqVmId.substr(0, reqVmId.size() -1);
    VirtualMachine vm = vmInfos[_reqVmType];
    dayAddReqs.emplace_back(Request{_op, _reqVmType, _reqVmId, vm.cpuCore, vm.memSize, vm.isDual});
}
void readDelRequest(string &op, string &reqVmId){
	string _op, _reqVmId;
    _op = op.substr(1, op.size()-2);
    _reqVmId = reqVmId.substr(0, reqVmId.size()-1);
    dayDelReqs.emplace_back(Request{_op, _reqVmId});
}
void readDayRequests(int dayReqNumber){
	string op, reqVmType, reqVmId;
	dayAddReqs.clear();//清空前一日的添加请求
	dayDelReqs.clear();//清空前一日的删除请求
	for (int i=0; i<dayReqNumber; i++){
		cin>>op;
		if(op[1] == 'a'){
			cin>>reqVmType>>reqVmId;
			readAddRequest(op, reqVmType, reqVmId);;
		}else{
			cin>>reqVmId;
			readDelRequest(op, reqVmId);
		}
	}
}
/**************************************************/

//用 双节点添加请求 去凑给定的服务器
vector<vector<DeployInfo>> dualMakeUpForServer(vector<Request> const &reqs, vector<Server> const &servers){
	vector<vector<DeployInfo>> ans;
	for(Server const &sv : servers){
		vector<DeployInfo> temp;
		int targetCpu=sv.cpuA + sv.cpuB;
		int targetMem=sv.memA + sv.memB;
		for(int i=0; i<reqs.size(); i++){
			Request req = reqs[i];
			if(targetCpu-req.vmCpu>=0 && targetMem-req.vmMem>=0){
				temp.emplace_back(DeployInfo{0, req.vmCpu/2, req.vmMem/2});//所部署到的服务器的编号暂无法确认，暂时设为 0 
				targetCpu -= req.vmCpu;
				targetMem -= req.vmMem;
			}else break;
		}
		ans.emplace_back(temp);
	}
	return ans;//最终的长度应该和传入的 servers 的长度一样
}
//用 单节点添加请求 去凑给定的服务器
vector<vector<DeployInfo>> sgleMakeUpForServer(vector<Request> const &reqs, vector<Server> const &servers){
	vector<vector<DeployInfo>> ans;
	for(Server const &sv : servers){
		vector<DeployInfo> temp;
		int cpuA=sv.cpuA, cpuB=sv.cpuB;
		int memA=sv.memA, memB=sv.memB;
		for(int i=0; i<reqs.size(); i++){
			Request req = reqs[i];
			if(cpuA>=req.vmCpu && memA>=req.vmMem){
				temp.emplace_back(DeployInfo{0, req.vmCpu, req.vmMem, 0});//所部署到的服务器的编号暂无法确认，暂时设为 0 
				cpuA -= req.vmCpu;
				memA -= req.vmMem;
			} else if (cpuB>=req.vmCpu && memB>=req.vmMem){
				temp.emplace_back(DeployInfo{0, req.vmCpu, req.vmMem, 1});//所部署到的服务器的编号暂无法确认，暂时设为 0 
				cpuB -= req.vmCpu;
				memB -= req.vmMem;
			}else{
				break;
			}
		}
		ans.emplace_back(temp);
	}
	return ans;//最终的长度应该和传入的 servers 的长度一样
}

void migrate(int day){
	vector<string> day_migrate_info{""};//用来存每日的迁移信息。先加入一个空字符串留给 migrate_num
	int max_migrate_num = vmDeployInfos.size()/200;//当日最大可迁移数量，不超过 max_migrate_num
	int migrate_num = 0;//当日已迁移数量
	
	
	day_migrate_info[0] = "(migration, " + to_string(migrate_num) + ")\n";//将migrate_num转化成字符串放到数组的首位
	migrate_info.emplace_back(day_migrate_info);//存一下每日的迁移信息
}

//购买部署服务器
void purchaseServers(int day){
	vector<string> buy_servers;//记录当天买的服务器。每台服务器的类型
	vector<vector<string>> sv_run_vms;//记录处理过程中每买一台服务器，其上部署的虚拟机的Id
	unordered_map<string, DeployInfo> vm_dep_infos;//记录处理过程中虚拟机的部署信息
	
	vector<Request> dualAddReqsGreat, dualAddReqsLess;//双部署 添加请求 (按核内比大于1小于1分类)
	vector<Request> sgleAddReqsGreat, sgleAddReqsLess;//单部署 添加请求 (按核内比大于1小于1分类)
	//将当日的添加请求分类。四个类别
	for(Request const &req : rest_dayAddReqs){
		if (req.isDual){
			if(req.ratio > 1) dualAddReqsGreat.emplace_back(req);
			else dualAddReqsLess.emplace_back(req);
		} else {
			if(req.ratio > 1) sgleAddReqsGreat.emplace_back(req);
			else sgleAddReqsLess.emplace_back(req);
		}
	}
	//各种部署请求的不同排序。注意理解精髓
	sort(dualAddReqsGreat.begin(), dualAddReqsGreat.end(), req_cmp_cpu_up);//核内比大于1，按照cpu升序排
	sort(dualAddReqsLess.begin(), dualAddReqsLess.end(), req_cmp_mem_up);//核内比小于1，按照mem升序排
	sort(sgleAddReqsGreat.begin(), sgleAddReqsGreat.end(), req_cmp_cpu_up);//核内比大于1，按照cpu升序排
	sort(sgleAddReqsLess.begin(), sgleAddReqsLess.end(), req_cmp_mem_up);//核内比小于1，按照mem升序排
	
	vector<Request> rest_reqs;
	//考虑 双节点 核内比 > 1 的添加请求如何买服务器部署
	rest_reqs = dualAddReqsGreat;
	while(rest_reqs.size() != 0){
		vector<vector<DeployInfo>> ans = dualMakeUpForServer(rest_reqs, greatServers);//得到每台服务器上最大可部署信息
		vector<DeployInfo> maxDep;
		int maxSize = -1, size, index=-1;//服务器greatServers[index]上最多能部署前maxSize条请求
		for(int i=0; i<ans.size(); i++){
			vector<DeployInfo> const &deps = ans[i];
			size = deps.size();
			if(size > maxSize){
				maxSize=size;
				maxDep=deps;
				index=i;
			}
		}
		Server sv = greatServers[index];//购买的服务器
		buy_servers.emplace_back(sv.type);//暂存一下该服务器
		sv_run_vms.emplace_back(vector<string>{});//该服务器上部署的虚拟机
		size = sv_run_vms.size()-1;
		for(int i=0; i<maxSize; i++){//遍历前maxSize条请求，每条请求对应maxDep中的一条部署信息
			string vmId = rest_reqs[i].vmId;
			sv_run_vms[size].emplace_back(vmId);
			vm_dep_infos[vmId] = maxDep[i];
		}
		rest_reqs.erase(rest_reqs.begin(), rest_reqs.begin()+maxSize);//删除前maxSize条请求
	}
	//考虑 双节点 核内比 < 1 的添加请求如何买服务器
	rest_reqs = dualAddReqsLess;
	while(rest_reqs.size() != 0){
		vector<vector<DeployInfo>> ans = dualMakeUpForServer(rest_reqs, lessServers);//得到每台服务器上最大可部署信息
		vector<DeployInfo> maxDep;
		int maxSize = -1, size, index=-1;//服务器lessServers[index]上最多能部署前maxSize条请求
		for(int i=0; i<ans.size(); i++){
			vector<DeployInfo> const &deps = ans[i];
			size = deps.size();
			if(size > maxSize){
				maxSize=size;
				maxDep=deps;
				index=i;
			}
		}
		Server sv = greatServers[index];//购买的服务器
		buy_servers.emplace_back(sv.type);//暂存一下该服务器
		sv_run_vms.emplace_back(vector<string>{});//该服务器上部署的虚拟机
		size = sv_run_vms.size()-1;
		for(int i=0; i<maxSize; i++){//遍历前maxSize条请求，每条请求对应maxDep中的一条部署信息
			string vmId = rest_reqs[i].vmId;
			sv_run_vms[size].emplace_back(vmId);
			vm_dep_infos[vmId] = maxDep[i];
		}
		rest_reqs.erase(rest_reqs.begin(), rest_reqs.begin()+maxSize);//删除前maxSize条请求
	}
	
	//考虑 单节点 核内比 > 1 的添加请求如何买服务器
	rest_reqs = sgleAddReqsGreat;
	while(rest_reqs.size() != 0){
		vector<vector<DeployInfo>> ans = sgleMakeUpForServer(rest_reqs, greatServers);//得到每台服务器上最大可部署信息
		vector<DeployInfo> maxDep;
		int maxSize = -1, size, index=-1;//服务器greatServers[index]上最多能部署前maxSize条请求
		for(int i=0; i<ans.size(); i++){
			vector<DeployInfo> const &deps = ans[i];
			size = deps.size();
			if(size > maxSize){
				maxSize=size;
				maxDep=deps;
				index=i;
			}
		}
		Server sv = greatServers[index];//购买的服务器
		buy_servers.emplace_back(sv.type);//暂存一下该服务器
		sv_run_vms.emplace_back(vector<string>{});//该服务器上部署的虚拟机
		size = sv_run_vms.size()-1;
		for(int i=0; i<maxSize; i++){//遍历前maxSize条请求，每条请求对应maxDep中的一条部署信息
			string vmId = rest_reqs[i].vmId;
			sv_run_vms[size].emplace_back(vmId);
			vm_dep_infos[vmId] = maxDep[i];
		}
		rest_reqs.erase(rest_reqs.begin(), rest_reqs.begin()+maxSize);//删除前maxSize条请求
	}
	//考虑 单节点 核内比 < 1 的添加请求如何买服务器
	rest_reqs = sgleAddReqsLess;
	while(rest_reqs.size() != 0){
		vector<vector<DeployInfo>> ans = sgleMakeUpForServer(rest_reqs, lessServers);//得到每台服务器上最大可部署信息
		vector<DeployInfo> maxDep;
		int maxSize = -1, size, index=-1;//服务器lessServers[index]上最多能部署前maxSize条请求
		for(int i=0; i<ans.size(); i++){
			vector<DeployInfo> const &deps = ans[i];
			size = deps.size();
			if(size > maxSize){
				maxSize=size;
				maxDep=deps;
				index=i;
			}
		}
		Server sv = greatServers[index];//购买的服务器
		buy_servers.emplace_back(sv.type);//暂存一下该服务器
		sv_run_vms.emplace_back(vector<string>{});//该服务器上部署的虚拟机 
		size = sv_run_vms.size()-1;
		for(int i=0; i<maxSize; i++){//遍历前maxSize条请求，每条请求对应maxDep中的一条部署信息
			string vmId = rest_reqs[i].vmId;
			sv_run_vms[size].emplace_back(vmId);
			vm_dep_infos[vmId] = maxDep[i];
		}
		rest_reqs.erase(rest_reqs.begin(), rest_reqs.begin()+maxSize);//删除前maxSize条请求
	}
	
	vector<string> day_buy_info=vector<string>{""};
	//处理 buy_servers, sv_run_vms, vm_dep_infos 的映射关系，并更新全局变量。这点很重要
	int svId = svResources.size();
	set<string> temp_set;
	unordered_map<int, int> temp_map;//做映射，好球麻烦哟
	for(int i=0; i<buy_servers.size(); i++){
		string svType=buy_servers[i];
		if(temp_set.find(svType)!=temp_set.end()) continue;
		int number=1;
		temp_set.insert(svType);
		svResources.emplace_back(svInfos[svType]);//买服务器放入全局变量中
		svRunVmsNumber.emplace_back(0);
		svRunVms.emplace_back(vector<string>{});
		temp_map[i]=svId++;//做好映射
		for(int j=i+1; j<buy_servers.size(); j++){
			if(buy_servers[j]==svType){
				svResources.emplace_back(svInfos[svType]);//买服务器放入全局变量中
				svRunVmsNumber.emplace_back(0);
				svRunVms.emplace_back(vector<string>{});
				temp_map[j]=svId++;//做好映射
				number++;
			}
		}
		SERVERCOST += svInfos[svType].serverCost * number;//购买的成本
		day_buy_info.emplace_back("(" + svType + ", " + to_string(number) + ")\n");
	}
	day_buy_info[0] = "(purchase, " + to_string(temp_set.size()) + ")\n";
	purchase_info.emplace_back(day_buy_info);//每天的购买信息
	
	//真正地调整服务器上的资源
	int needCpu, needMem;
	for(int i=0; i<sv_run_vms.size(); i++){
		string svType = buy_servers[i];
		svId = temp_map[i];
		Server &sv = svResources[svId];//真正买的服务器，减少资源
		for(string const &vmId:sv_run_vms[i]){
			DeployInfo &depInfo = vm_dep_infos[vmId];
			needCpu=depInfo[1], needMem=depInfo[2];
			if(depInfo.size()==3){
				sv.cpuA -= needCpu;
				sv.cpuB -= needCpu;
				sv.memA -= needMem;
				sv.memB -= needMem;
			}else{
				if(depInfo[3]==0){
					sv.cpuA -= needCpu;
					sv.memA -= needMem;
				}else{
					sv.cpuB -= needCpu;
					sv.memB -= needMem;
				}
			}
			depInfo[0] = svId;//重新设置一下部署到的服务器编号
			vmDeployInfos[vmId]=depInfo;//更新全局变量
			svRunVmsNumber[svId]++;
			svRunVms[svId].emplace_back(vmId);
		}
	}
}

//处理一天的请求
void handleOneDayRequests(int day){
	migrate(day);
	
	rest_dayAddReqs.clear();
	
	for(Request const &req : dayAddReqs){
		string vmId = req.vmId;
		int isDual = req.isDual;
		int needCpu = isDual==1 ? req.vmCpu/2 : req.vmCpu;
		int needMem = isDual==1 ? req.vmMem/2 : req.vmMem;
		for(int i=0; i<svResources.size(); i++){
			Server &sv = svResources[i];
			if(isDual==1){
				if(sv.cpuA>=needCpu && sv.cpuB>=needCpu && sv.memA>=needMem && sv.memB>=needMem){
					sv.cpuA -= needCpu;
					sv.cpuB -= needCpu;
					sv.memA -= needMem;
					sv.memB -= needMem;
					vmDeployInfos[vmId] = DeployInfo{i, needCpu, needMem};
					svRunVmsNumber[i]++;
					svRunVms[i].emplace_back(vmId);
					break;
				}
			}else{
				if(sv.cpuA >= sv.cpuB){//A节点剩得多
					if(sv.cpuA>=needCpu && sv.memA>=needMem){//并且A节点能放下
						sv.cpuA -= needCpu;
						sv.memA -= needMem;
						vmDeployInfos[vmId] = DeployInfo{i, needCpu, needMem, 0};
						svRunVmsNumber[i]++;
						svRunVms[i].emplace_back(vmId);
						break;
					}
					if(sv.cpuB>=needCpu && sv.memB>=needMem){//虽然A节点剩得多，但是A节点放不下，那么看B节点能不能放下
						sv.cpuB -= needCpu;
						sv.memB -= needMem;
						vmDeployInfos[vmId] = DeployInfo{i, needCpu, needMem, 1};
						svRunVmsNumber[i]++;
						svRunVms[i].emplace_back(vmId);
						break;
					}
				}else{//B节点剩得多
					if(sv.cpuB>=needCpu && sv.memB>=needMem){//并且B节点能放下
						sv.cpuB -= needCpu;
						sv.memB -= needMem;
						vmDeployInfos[vmId] = DeployInfo{i, needCpu, needMem, 1};
						svRunVmsNumber[i]++;
						svRunVms[i].emplace_back(vmId);
						break;
					}
					if(sv.cpuA>=needCpu && sv.memA>=needMem){//虽然B节点剩得多，但是B节点放不下，那么看A节点能不能放下
						sv.cpuA -= needCpu;
						sv.memA -= needMem;
						vmDeployInfos[vmId] = DeployInfo{i, needCpu, needMem, 0};
						svRunVmsNumber[i]++;
						svRunVms[i].emplace_back(vmId);
						break;
					}
				}
			}
		}
		rest_dayAddReqs.emplace_back(req);
	}
	
	
	purchaseServers(day);//为剩余的添加请求考虑购买服务器部署
	
	//保存部署信息
	vector<string> day_deploy_info;
	for(Request const &req : dayAddReqs){//遍历当日最原始的添加请求
		string vmTyep=req.vmType;
		DeployInfo const &depInfo = vmDeployInfos[req.vmId];
		string svId = to_string(depInfo[0]);
		if(depInfo.size()==3){
			day_deploy_info.emplace_back("(" + svId + ")\n");
		}else{
			string nodeInfo = depInfo[3]==0 ? "A" : "B";
			day_deploy_info.emplace_back("(" + svId + ", " + nodeInfo + ")\n");
		}
	}
	deploy_info.emplace_back(day_deploy_info);
	
	
	for(Request const &req : dayDelReqs){//考虑删除请求
		string vmId = req.vmId;
		DeployInfo const &depInfo = vmDeployInfos[vmId];
		int svId = depInfo[0];
		Server &sv = svResources[svId];
		int isDual = depInfo.size()==3 ? 1 : 0;
		int occupiedCpu=depInfo[1], occupiedMem=depInfo[2];
		if(isDual==1){
			sv.cpuA += occupiedCpu;
			sv.cpuB += occupiedCpu;
			sv.memA += occupiedMem;
			sv.memB += occupiedMem;
		}else{
			if(depInfo[3]==0){
				sv.cpuA += occupiedCpu;
				sv.memA += occupiedMem;
			}else{
				sv.cpuB += occupiedCpu;
				sv.memB += occupiedMem;
			}
		}
		svRunVmsNumber[svId]--;
		vector<string> &VMIDS=svRunVms[svId];
		VMIDS.erase(remove(VMIDS.begin(), VMIDS.end(), vmId), VMIDS.end());//没错删除就是这么复杂
		svRunVms[svId].emplace_back(vmId);
		vmDeployInfos.erase(vmId);//删除该条部署信息
	}
}

//打印输出结果
void print(){
	for(int i=0; i<purchase_info.size(); i++){//遍历每天
		for(string &info:purchase_info[i]){//每天购买
			cout<<info;
		}
		for(string &info:migrate_info[i]){//每天迁移
			cout<<info;
		}
		for(string &info:deploy_info[i]){//每天部署
			cout<<info;
		}
	}
}

//计算每日的耗电成本
void computePowerCost(){
	for(int i=0; i<svRunVmsNumber.size(); i++){
        if(svRunVmsNumber[i] > 0){
            POWERCOST += svResources[i].powerCost;
        }
    }
}

void cloudResourceSchedulingAlgorithm(){
	readServerAndVmInfos();//读取服务器和虚拟机信息，并得到所需数据
	int reqDays=0, dayReqNumber=0;
	scanf("%d", &reqDays);
	for (int day=0; day<reqDays; day++){
		scanf("%d", &dayReqNumber);
		readDayRequests(dayReqNumber);
		handleOneDayRequests(day);
		computePowerCost();
		if(day==0 || day%50==0) printf("Finished requests of day : %d\n", day);
	}
	//print();//打印输出结果
}

int main(){
	//	freopen(OUTPUT_REDIRECTION, "w", stdout);
	clock_t start, finish;
	
	//第一份文件
	start = clock();
	freopen(INPUT_REDIRECTION_1, "r", stdin);
	cloudResourceSchedulingAlgorithm();
	finish = clock();
	TOTALCOST = SERVERCOST + POWERCOST;//总成本
	SC += SERVERCOST, PC += POWERCOST, TC += TOTALCOST;
	printf("\nCompute Time: %f s \n", double(finish-start)/CLOCKS_PER_SEC);
	printf("Server Cost: %lld \nPower Cost: %lld \nTotal Cost: %lld \n", SERVERCOST, POWERCOST, TOTALCOST);
	
	return 0;
}